package com.atguigu.gmall.realtime.util;

import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.IOException;
import java.io.StringReader;
import java.util.HashSet;
import java.util.Set;

/**
 * @author Archie
 * @date 2021-10-27 21:00
 * @description
 */
public class IkUtil {

	public static void main(String[] args) {
		System.err.println(split("我是中国人"));
	}

	public static Set<String> split(String keyword) {
		Set<String> words = new HashSet<>();
		StringReader reader = new StringReader(keyword); // 读入为 内存流

		IKSegmenter segmenter = new IKSegmenter(reader, true);
		try {
			Lexeme next = segmenter.next();
			while (next != null) {
				words.add(next.getLexemeText());
				next = segmenter.next();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return words;
	}

}
